package com.itcv.util;


import org.objectweb.asm.ClassReader;
import org.objectweb.asm.util.ASMifier;
import org.objectweb.asm.util.Printer;
import org.objectweb.asm.util.Textifier;
import org.objectweb.asm.util.TraceClassVisitor;

import java.io.IOException;
import java.io.PrintWriter;

public class PrintAsm {

    public static void main(String[] args) {
        String className = "demo.HelloWorld";
        int parsingOptions = ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG;
        boolean asmCode = true;

        //打印结果
        try {
            Printer printer = asmCode ? new ASMifier() : new Textifier();
            PrintWriter pw = new PrintWriter(System.out,true);
            TraceClassVisitor tcv = new TraceClassVisitor(null,printer,pw);
            new ClassReader(className).accept(tcv,parsingOptions);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
